Introduction
In this report, we came up with suggestions on where to place Bike
Share stations to increase riderships based on many variables, such as
the location of the current bike share stations, the placement of signed
bike routes, and the locations where people take vehicles as their main
mode of transportation versus take public transportaition as their main
mode of transportation.
Load Appropriate Packages
library(knitr)
library(tidyverse)
library(janitor)
library(here)
library(sf)
library(tmap)
library(tidycensus)
Knitr is used for properly transforming the r notebook into an html
file. The tidyverse is used to tidy data using other packages within in
such as dplyr. The janitor packages is used to clean up the variable
names from the data sets. The here library is used to locate files on
the computer to make it easier to load in the data sets. The sf library
is used to work with spatial data. The tmap library is used to create
interaactive maps. The tidycensus data is used to get data from the U.S
Census Bureau data via codes.
Read in the captial bike share data
bikes = (read.csv(here("data_raw", "202309-capitalbikeshare-tripdata.csv"))) |> clean_names()
Read in the Captial Bikeshare Station Locations
racks = st_read((here("data_raw", "Capital_Bikeshare_Locations.geojson"))) |> clean_names()
Reading layer `Capital_Bikeshare_Locations' from data source `C:\Users\thistljy\Documents\ds241_final\data_raw\Capital_Bikeshare_Locations.geojson' using driver `GeoJSON'
Simple feature collection with 754 features and 27 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: -77.36842 ymin: 38.78264 xmax: -76.82554 ymax: 39.12584
Geodetic CRS: WGS 84
Api Key to access the census data
census_api_key("9fc5d3792d3a5e922287c3f4e9995118766d50a2")
To install your API key for use in future sessions, run this function with `install = TRUE`.
Loading in the codes that is linked to access the specific census
data
v2018 = load_variables(2018, "acs5")
Load the relevant data from the 2017-2021 Census Data for Washington
DC
df_censcus=get_acs(geography = "tract",
variables=c("vehicles"="B08141_001",
"population" = "B01001_001",
"public_transportion" = "B08006_008"),
state="DC",geometry=TRUE,year=2021)
Getting data from the 2017-2021 5-year ACS
Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
Using FIPS code '11' for state 'DC'
For this analysis, we will need the amount of vehiclces used in a
specific location in Washington D.c., the population for each area in
Washington D.C., and the usage of public transportation in those same
areas.
Make sure our data frames plot
plot(df_censcus)

plot(racks)
Warning: plotting the first 9 out of 27 attributes; use max.plot = 27 to plot all

Make each observation of vehicles, population, and public
transportation into their own columns
tmap_mode("view")
tmap mode set to interactive viewing
df_cens=df_censcus %>%
select(-moe) %>%
pivot_wider(names_from = "variable",
values_from = "estimate")|>
mutate(pub_pop = public_transportion / population,
v_pop = vehicles / population)
Read the Signed Bike Routes data into a spatial data frame.
bike_routes = st_read((here("data_raw", "Signed_Bike_Routes.geojson"))) |> clean_names()
Reading layer `Signed_Bike_Routes' from data source `C:\Users\thistljy\Documents\ds241_final\data_raw\Signed_Bike_Routes.geojson' using driver `GeoJSON'
Simple feature collection with 1024 features and 37 fields
Geometry type: LINESTRING
Dimension: XY
Bounding box: xmin: -77.08773 ymin: 38.8404 xmax: -76.92188 ymax: 38.98634
Geodetic CRS: WGS 84
Plot data
df_cens_adj = df_cens |> st_transform(4326)
bike_routes = st_as_sf(bike_routes, crs=st_crs(df_cens_adj))
racks = st_as_sf(racks, crs=st_crs(df_cens_adj))
tm_shape(df_cens) +tm_polygons(c("pub_pop", "v_pop"), alpha=.5) + tm_shape(racks) +tm_symbols(size = 0.1, alpha = 0.5) +
tm_shape(bike_routes) + tm_lines(col="blue",lwd=1,alpha= 1)